import 'package:flutter_pink_app/net/base/response.dart';
import '../net/index.dart';
import '../net/adater/dio_adapter.dart';
import '../net/request/recommend.request.dart';
import '../serialized/recommend.dart';
import '../util.dart';

const successStatus = 'SUCCESS.'; // 首页请求成功标识码

// 首页推荐栏请求业务接口
Future<HomeSerializedGen> getHomeRecommend(
    {int amount = 10, int pageIndex = 1}) async {
  final network = NetworkCall.getInstance(adapter: DioAdapter());
  BaseResponse<Map<String, dynamic>> response; // 响应报文
  try {
    response = await network
        .send<Map<String, dynamic>>(RecommendRequest(pageIndex, amount));
  } catch (e) {
    logCurrStackTrace(); // 打印当前堆栈信息
    print('请求首页推荐接口时发生错误。$e');
    return null;
  }
  assert(response.message == successStatus, '请求首页推荐接口返回的数据状态码不正确');
  // 如果请求状态成功则执行序列化
  return HomeSerializedGen.fromJson(response.data);
}
